#!/usr/bin/perl
#lvformat.cgi
require './lvm-lib.pl';
&ReadParse();

my ($err_msg, $log_ev, $log_msg, $log_pri);
my ($lvdev, $voldir, @lvinfo, $l, $lv);
$config{'mkfs_lock_new'} = "/var/nas/lock/mkfsd_new";
$err_msg="";
$log_ev="";

$lvname = $in{'lvname'};
$vg = $in{'lvvg'};
$passwd = $in{'lvpass'};
$lvdev = "/dev/$vg/$lvname";
$err_msg = "$lvname|$vg|$passwd|$lvdev";
#goto ERROR_OUT;

#cryptsetup lv and mount
if(-e "/dev/mapper/$lvname"){
	`cryptsetup remove $lvname`;
}
$out1 = `echo $passwd|cryptsetup create $lvname $lvdev`;
$rc = $?>>8;
if($rc){
	$err_msg = "Failed!";
	goto ERROR_OUT;
}
$newlvdev = "/dev/mapper/$lvname";
$volpath = "/usrvol/$lvname";
$out2 = `mount -o usrquota -o grpquota $newlvdev $volpath`;

$rc = $?>>8;
if($rc){
	`cryptsetup remove $lvname`;
	$err_msg = $text{'err_password'};
	goto ERROR_OUT;
}
&redirect("index.cgi");
ERROR_OUT:
&error_setup($text{'crt_err_title'});
&error($err_msg);


